package a2025_02_21;

public class MyStack {
    int[] stack;
    int useSized;
    int InitSize=10;

    public MyStack(){
        stack=new int[InitSize];
        useSized=0;
    }

    public void push(int elem){
        if(useSized>=stack.length){
            grow();
        }
        stack[useSized++]=elem;
    }

    public int pop(){
        if(!isEmpty()){
            return stack[--useSized];
        }
        return -1;
    }

    public int peek(){
        if(!isEmpty()){
            return stack[useSized-1];
        }
        return -1;
    }

    public void grow(){
        int[] temp=new int[stack.length+10];
        for(int i=0;i<stack.length;i++){
            temp[i]=stack[i];
        }
        stack=temp;
    }

    public boolean isEmpty(){
        return useSized==0;
    }
}
